package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.mapper.user.UserDishMapper;
import com.sky.mapper.user.UserSetmealMapper;
import com.sky.service.UserSetmealService;
import com.sky.vo.DishItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserSetmealServiceImpl implements UserSetmealService {

    @Autowired
    private UserSetmealMapper userSetmealMapper;


    // 根据分类id查询套餐
    @Override
    public List<Setmeal> list(Setmeal setmeal) {
        LambdaQueryWrapper<Setmeal> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(setmeal.getStatus() != null, Setmeal::getStatus, setmeal.getStatus())
                .eq(setmeal.getCategoryId() != null, Setmeal::getCategoryId, setmeal.getCategoryId());

        return userSetmealMapper.selectList(wrapper);
    }

    // 根据套餐id查询包含的菜品列表
    @Override
    public List<DishItemVO> getDishItemById(Long setmealId) {
        // 根据 setmeal_dish表 获得 name 和 copies
        // 根据 dish表 获得 image 和 description
        // select sd.name as name, sd.copies as copies from sky_take_out.setmeal_dish sd left join sky_take_out.dish d on sd.dish_id = d.id where sd.setmeal_id = #{setmealId}
        List<DishItemVO> dishItemVOS = userSetmealMapper.getDishItemById(setmealId);
        return dishItemVOS;
    }
}
